package com.skyline.energy.transaction;

import java.sql.Connection;

public enum IsolationLevel {
	ISOLATION_READ_UNCOMMITTED {
		public int toJdbcIsolation() {
			return Connection.TRANSACTION_READ_UNCOMMITTED;
		}
	},
	ISOLATION_READ_COMMITTED {
		public int toJdbcIsolation() {
			return Connection.TRANSACTION_READ_COMMITTED;
		}
	},
	ISOLATION_REPEATABLE_READ {
		public int toJdbcIsolation() {
			return Connection.TRANSACTION_REPEATABLE_READ;
		}
	},
	ISOLATION_SERIALIZABLE {
		public int toJdbcIsolation() {
			return Connection.TRANSACTION_SERIALIZABLE;
		}
	},
	ISOLATION_NONE {
		public int toJdbcIsolation() {
			return Connection.TRANSACTION_NONE;
		}
	},
	ISOLATION_DEFAULT {
		public int toJdbcIsolation() {
			return -1;
		}
	};

	public abstract int toJdbcIsolation();

	public static IsolationLevel toIsolationLevel(int isolationLevel) {
		switch (isolationLevel) {
		case Connection.TRANSACTION_READ_COMMITTED:
			return ISOLATION_READ_COMMITTED;
		case Connection.TRANSACTION_READ_UNCOMMITTED:
			return ISOLATION_READ_UNCOMMITTED;
		case Connection.TRANSACTION_REPEATABLE_READ:
			return ISOLATION_REPEATABLE_READ;
		case Connection.TRANSACTION_SERIALIZABLE:
			return ISOLATION_SERIALIZABLE;
		case Connection.TRANSACTION_NONE:
			return ISOLATION_NONE;
		default:
			return ISOLATION_DEFAULT;
		}
	}
}
